package net.maku.project.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.project.convert.ProjectReportConvert;
import net.maku.project.query.ProjectReportQuery;
import net.maku.project.service.ProjectReportService;
import net.maku.project.vo.ProjectReportVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @FileName: projectReportController
 * @Project: maku-boot-zzhl
 * @Package: net.maku.project.controller
 * @Author: Aili
 * @Date: 2024/7/23 0:15
 * @Version: 1.0.0
 * @Description: projectReportController Description
 */
@RestController
@RequestMapping("project/projectReport")
@Tag(name="项目进度表")
@AllArgsConstructor
public class ProjectReportController {
    private final ProjectReportService projectReportService;



    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('project:project-report:page')")
    public Result<PageResult<ProjectReportVO>> page(@ParameterObject @Valid ProjectReportQuery query){
        PageResult<ProjectReportVO> page = projectReportService.page(query);

        return Result.ok(page);
    }
    //通过项目id查询项目进度表
    @GetMapping("/projectdetail/{projectId}")
    @Operation(summary = "根据项目编号查询")
    @PreAuthorize("hasAuthority('project:project-report:list')")
    public List<ProjectReportVO> findAllByProjectId(@PathVariable Long projectId){
        return projectReportService.findAllByProjectId(projectId);
    }

    //上报本周进度
    @PostMapping ("/report")
    @Operation(summary = "上报本周进度")
    @Tag(name="项目进度表") // 为Swagger文档添加描述
    public Result<String> report(@RequestBody @Valid ProjectReportVO vo){
        projectReportService.insert(ProjectReportConvert.INSTANCE.convert(vo));
        return Result.ok();
    }

}
